use chrono::prelude::*;
use polars::prelude::*;

#[derive(Debug)]
struct Person {
    name: String,
    birthdate: NaiveDate,
    weight: f64, // (kg)
    height: f64, // (m)
}
fn main() {
    let mut df: DataFrame = df!(
    "name" => ["Alice Archer", "Ben Brown", "Chloe Cooper"],
    "birthdate" => [
    NaiveDate::from_ymd_opt(1997, 1, 10).unwrap(),
    NaiveDate::from_ymd_opt(1985, 2, 15).unwrap(),
    NaiveDate::from_ymd_opt(1983, 3, 22).unwrap(),
    ],
    "weight" => [57.9, 72.5, 53.6], // (kg)
    "height" => [1.56, 1.77, 1.65], // (m)
    )
    .unwrap();
    println!("{}", df);

    let rowcnt = df.height();
    let col1 = df["name"].str().unwrap();
    let col2 = df["birthdate"].date().unwrap();
    let col3 = df["weight"].f64().unwrap();
    let col4 = df["height"].f64().unwrap();

    let mut persons: Vec<Person> = Vec::new();
    for i in 0..rowcnt {
        let name: String = col1.get(i).unwrap().to_string();
        let days: i32 = col2.get(i).unwrap();
        let base_date = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
        let date = base_date + chrono::Duration::days(days as i64);
        let weight: f64 = col3.get(i).unwrap();
        let height: f64 = col4.get(i).unwrap();
        //println!("{} {} {} {}", name, date, weight, height);
        persons.push(Person {
            name: name,
            birthdate: date,
            weight: weight,
            height: height,
        });
    }
    for person in persons.iter() {
        println!("{:?}", person);
    }
}
